#!/usr/bin/env python
# -*- coding: utf-8 -*-
#

#
# This program is free software; you can redistribute it and/or modify  
# it under the terms of the GNU General Public License as published by  
# the Free Software Foundation; either version 2 of the License, or     
# (at your option) any later version.                                   
#                                                                         
# A copy of the license can be found in the license.txt file supplied   
# with this software or at: http://www.gnu.org/copyleft/gpl.html       
#

import celtuce.help.logging as logging

import time


class   Celler(object) :
    #def __new__(cls) :
    #    self = object.__new__(cls)
    #    self._handler = Handler(self.event_queue, self.handle)
    #    return self
    #    ## __new__()

    def __init__(self) :
        self._id_base = id(self)
        self._id_serial = 1 
        self._id_maximum = 1024 * 1024 * 1024

        self._logger = logging.getLogger('celtuce')
        ## __init__()

    def handle(self, event_request) :
        '''handle request event, and must be overload

        @param event_request Event object of request

        @return None
        '''
        pass
        ## handle()

    def start(self) :
        self._logger.info('%s.start()', self.__class__.__name__)
        ## start()

    def stop(self) :
        self._logger.info('%s.stop()', self.__class__.__name__)
        ## stop()


    def genRequestID(self) :
        # TODO: lock
        serial = self._id_serial

        self._id_serial += 1
        if self._id_serial >= self._id_maximum :
            self._id_serial = 1

        id = '.'.join((str(self._id_base), str(serial)))
        return id
        ## genRequestID()

    ## class Celler


